// 定义Parent组件
const Parent = {
  template: `
  <div>{{name}}, 有{{money}}元</div>
  <div><button @click="giveZhuxiaomingMoney">提醒朱小明要生活费</button></div>
  <hr>
  <Child ref="zhuxiaoming" name="朱小明" @requestMoney="giveMoney" :giveMoney="giveMoney" />
  `,
  components: {
    Child: Child,
  },
  inject: ['$bus'],
  data() {
    return {
      name: '父组件', // 初始化一个的数据
      money: 10000,
    };
  },
  created() {
    this.$bus.on('requestMoneyByBus',this.giveMoney);
  },
  methods: {
    giveMoney(n) {
      this.money -= n;
    },
    giveZhuxiaomingMoney() {
       this.$refs.zhuxiaoming.askMoneyByEmit();
    }
  }
};